/*
 * @lc app=leetcode.cn id=28 lang=golang
 *
 * [28] 找出字符串中第一个匹配项的下标
 */
package main

import (
	"fmt"
	"strings"
)

// @lc code=start
func strStr(haystack string, needle string) int {
	nlen := len(needle)
	hlen := len(haystack)
	if nlen == 0 {
		return 0
	}
	for i := 0; i < len(haystack); i++ {
		if haystack[i] == needle[0] && i+nlen <= hlen {
			if haystack[i:i+nlen] == needle {
				return i
			}
		}
	}
	return -1
}

// @lc code=end

func strStr2(haystack string, needle string) int {
	return strings.Index(haystack, needle)
}

func main() {
	ret := strStr("strStr2ello", "ll")
	fmt.Println(ret)
}
